import 'package:flutter/material.dart';
import 'package:flutter_trip/page/home_page.dart';
import 'package:flutter_trip/page/my_page.dart';
import 'package:flutter_trip/page/search_page.dart';
import 'package:flutter_trip/page/travel_page.dart';
class TabNavigator extends StatefulWidget {
  const TabNavigator({super.key});

  @override
  State<TabNavigator> createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue;
  int _currentIndex = 0;
  final PageController _controller = PageController(
    initialPage: 0,
  );


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        onPageChanged: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        physics: const NeverScrollableScrollPhysics(),
        children: const [
          HomePage(),
          SearchPage(
            hideLeft: true,
          ),
          TravelPage(),
          MyPage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
            _controller.jumpToPage(index);
          });
        },
        fixedColor: _activeColor,
        type: BottomNavigationBarType.fixed,
        items: [
          _bottomItem(Icons.home, '首页'),
          _bottomItem(Icons.search, '搜索'),
          _bottomItem(Icons.camera_alt, '旅拍'),
          _bottomItem(Icons.account_circle, '我的'),
        ],
      ),
    );
  }

  _bottomItem(IconData icon, String text) {
    return BottomNavigationBarItem(
        icon: Icon(icon, color: _defaultColor),
        activeIcon: Icon(icon, color: _activeColor),
        label: text);
  }
}
